package com.sky.merchant.service;

import com.sky.common.core.domain.AjaxResult;
import com.sky.merchant.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
//@Order(Ordered.HIGHEST_PRECEDENCE)
public class MyGlobalExceptionHandler {

    @ExceptionHandler(CustomException.class)
    public AjaxResult handleCustomException( CustomException ex, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',发生自定义异常.", requestURI);
        return  AjaxResult.error(ex.getCode(),ex.getMessage());
    }

}